package com.lanou.elh.sso.web.controller;

import com.lanou.elh.sso.entity.Member;
import com.lanou.elh.sso.service.MemberService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/member")
public class MemberController {
    @Autowired
    private MemberService memberService;

    @PostMapping("/login")
    @ApiOperation(value = "用户登录")
    public Map<String, Object> login(@RequestBody Map<String, Object> map) {
        Member member = memberService.login(map);
        if (member != null) {
            String token = memberService.getToken(map);
            Map<String, Object> token1 = new HashMap<>();
            token1.put("token", token);
            return token1;
        }
        return map;
    }

    public Map<String,Object> getUser(String token){
        Member member = memberService.getMember(token);
        Map<String,Object> map = new HashMap<>();
        return map;
    }
}
